package invoice.view;

import java.util.Scanner;

public class MainMenu {
    private String preMenu;
    private String[] choice=new String[8];
    private String preChoice;
    public MainMenu(){
        preMenu="Select the following number:";
        choice[0]="1:Show files content";
        choice[1]="2:Add a new invoice line";
        choice[2]="3:Update a selected invoice line";
        choice[3]="4:Delete a selected invoice line";
        choice[4]="5:Add Chinese-style header and footer";
        choice[5]="6:Add English-style header and footer";
        choice[6]="7:Add mixed header and footer";
        choice[7]="8:Exit";
        preChoice="Your selection is ";

        while(true){
            printMainMenu();
            selectMenuLine(getInput());
        }
    }

    public static void main(String[] args){
        new MainMenu();
    }

    public void printMainMenu(){
        System.out.println("\n"+preMenu);
        for(String c:choice)
            System.out.println(c);
    }

    public short getInput(){
        Scanner input=new Scanner(System.in);
        if(input.hasNextShort()){
            short input_num=input.nextShort();
            //input.close();
            return input_num;
        }
        return 0;
    }

    public void selectMenuLine(short input){
        switch(input){
            case 1:System.out.println(preChoice+choice[0]+"\n");
                break;
            case 2:System.out.println(preChoice+choice[1]+"\n");
                break;
            case 3:System.out.println(preChoice+choice[2]+"\n");
                break;
            case 4:System.out.println(preChoice+choice[3]+"\n");
                break;
            case 5:System.out.println(preChoice+choice[4]+"\n");
                break;
            case 6:System.out.println(preChoice+choice[5]+"\n");
                break;
            case 7:System.out.println(preChoice+choice[6]+"\n");
                break;
            case 8:System.out.println(preChoice+choice[7]+"\n");
            default:System.exit(0);
        }
        try{
            Thread.sleep(1000);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
